import { createRouter, createWebHistory } from 'vue-router'
//从modules文件中读取路由
const files = import.meta.glob('./modules/*.js', { eager: true })
const moduleRoutes = []
for (const key in files) {
  moduleRoutes.push(...files[key].default)
}
const routes = [
  {
    path: '/',
    redirect: '/index'
  },

  {
    path: '/index',
    component: () => import('@/views/index.vue'),
    redirect: '/home',
    children: [
      {
        name: 'home',
        path: '/home',
        component: () => import('@/views/home.vue'),
        meta: {
          title: '首页'
        }
      },
      ...moduleRoutes
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'not-found',
    component: () => import('@/views/notFound.vue')
  }
]
const router = createRouter({
  // 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHistory(),
  routes
})

export default router
